package com.lonwin.mes2u8.domain.mes;

import com.google.common.collect.Lists;
import com.lonwin.mes2u8.domain.u8.U8MaterialOutHandlerResult;
import com.lonwin.mes2u8.domain.u8.U8MaterialOutHandlerResultInfo;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author DELL
 * @Date 2023-12-21 9:37
 */
@Data
public class MesMaterialOutQueryResult {
    // 批次号
    private String sno;
    // 产品标识
    private String spono;
    // 产品类型
    private String protype;
    // 物料编号
    private String mno;
    // 物料名称
    private String mdes;
    // 数量
    private BigDecimal num;
    // 总重
    private BigDecimal sumRealityBlanking;

    public U8MaterialOutHandlerResult convertToU8BillHandlerResult() {
        return U8MaterialOutHandlerResult.builder()
                .batchCode(getSno()).inventoryCode(getSpono())
                .infoList(Lists.newArrayList(U8MaterialOutHandlerResultInfo.builder()
                        .mno(getMno()).mdes(getMdes()).weight(getSumRealityBlanking()).build()))
                .build();
    }

    public static MesMaterialOutQueryResult convertResultBySameMno(List<MesMaterialOutQueryResult> resultList) {
        MesMaterialOutQueryResult first = resultList.stream().findFirst().get();
        BigDecimal sum = BigDecimal.ZERO;

        for (MesMaterialOutQueryResult mesMaterialOutQueryResult : resultList) {
            if (first.getMno().equals(mesMaterialOutQueryResult.getMno())) {
                sum = sum.add(mesMaterialOutQueryResult.getSumRealityBlanking());
            }
        }

        first.setSumRealityBlanking(sum);
        return first;
    }




}
